import request from "@/utils/request";
import type {
  SpuImageList,
  GetProductSPU,
  SpuSaleAttrList,
  GetProductSpuParams,
  GetBaseSaleAttrList,
  AddOrUpdateSpuParams,
} from "./model/spuModel";
import { TrademarkList } from "./model/trademarkModel";

enum api {
  getProductSPUList = "/admin/product",
  getTrademarkList = "/admin/product/baseTrademark/getTrademarkList",
  getBaseSaleAttrList = "/admin/product/baseSaleAttrList",
  addSpuList = "/admin/product/saveSpuInfo",
  getSpuImageList = "/admin/product/spuImageList",
  getSpuSaleAttrList = "/admin/product/spuSaleAttrList",
  updateSpuList = "/admin/product/updateSpuInfo",
}
/**
 * 修改SPU的接口
 * @param data AddOrUpdateSpuParams
 * @returns null
 */
export const updateSpuListApi = (data: AddOrUpdateSpuParams) => {
  return request.post<any, null>(api.updateSpuList, data);
};

/**
 * 获得销售属性列表的请求
 * @param spuId number
 * @returns
 */
export const getSpuSaleAttrListApi = (spuId: number) => {
  return request.get<any, SpuSaleAttrList>(
    api.getSpuSaleAttrList + `/${spuId}`
  );
};

/**
 * 获得图片列表的请求
 * @param spuId number
 * @returns SpuImageList
 */
export const getSpuImageListApi = (spuId: number) => {
  return request.get<any, SpuImageList>(api.getSpuImageList + `/${spuId}`);
};

/**
 * 添加SPU的接口
 * @param data AddOrUpdateSpuParams
 * @returns null
 */
export const addSpuListApi = (data: AddOrUpdateSpuParams) => {
  return request.post<any, null>(api.addSpuList, data);
};

/**
 * 获取销售属性的接口
 * @returns GetBaseSaleAttrList
 */
export const getBaseSaleAttrListApi = () => {
  return request.get<any, GetBaseSaleAttrList>(api.getBaseSaleAttrList);
};

/**
 * 获取品牌数据的接口
 * @returns TrademarkList
 */
export const getTrademarkListApi = () => {
  return request.get<any, TrademarkList>(api.getTrademarkList);
};

/**
 * 获取SPU的请求
 * @param param0 getProductSpuParams
 * return getProductSPU
 */
export const getProductSPUListApi = ({
  page,
  limit,
  category3Id,
}: GetProductSpuParams) => {
  return request.get<any, GetProductSPU>(
    api.getProductSPUList + `/${page}/${limit}`,
    {
      params: {
        category3Id,
      },
    }
  );
};
